// 导入axios
// import axios from 'axios'
import {API} from './api'
export const getCurentCity=()=>{
    const localCity = JSON.parse(localStorage.getItem('ytzf_city'))
    if(!localCity){
       return new Promise((resolve,reject)=>{
            // 如果没有
        const curCity =new BMapGL.LocalCity()
		curCity.get(async (res)=>{
			try{
                const result=await API.get(`/area/info?name=${res.name}`)
			// 保存到本地存储中
            localStorage.setItem('ytzf_city',JSON.stringify(result.data.body))
            resolve(result.data.body)     
            }catch(e){
                // 获取定位城市失败
                reject(e)
            }
		})
       })
    }
    return Promise.resolve(localCity)
}